public class Serializer
extends java.lang.Object
Serializer is powerful utility class that allows you to serialize any object in Java using universal protocol system.
This system is generating code similar to JSON called SerialX but unlike JSON, SerialX is based on determinate order of arguments.
Also works with regular Java Base64 serialization.| Modifier and Type | Class and Description |
|---|---|
static class |
Serializer.ProtocolRegistry
ProtocolRegistry, place to register protocols!
|
| Modifier and Type | Field and Description |
|---|---|
static java.text.DecimalFormat |
decimalFormatter
Decimal formatter to format decimal numbers (double, float) with during serialization!
Default
DecimalFormat will round decimal numbers to 3 decimal places (format pattern #.###)!
Set this on null and decimal numbers will not be formated! Do this when you need accuracy! |
static boolean |
generateComments
Set this on true and program will generate comments and report!
|
static java.util.Map<java.lang.String,java.lang.Object> |
globalVariables
Map with global variables, accessible for any serialized content (key is variable name, value is vale).
|
static Serializer.ProtocolRegistry |
PROTOCOL_REGISTRY
This is serialization protocol registry.
|
static boolean |
useProtocolIfCan
Set this on true to force program to use SerializationProtocol also on java.io.Serializable objects.
|
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
Code(java.lang.String code) |
static java.lang.String |
Comment(java.lang.String comment) |
static java.lang.String |
LoadFileToString(java.io.File f) |
static java.util.List<java.lang.Object> |
LoadFrom(java.io.File f) |
static java.util.List<java.lang.Object> |
LoadFromString(java.lang.String str) |
static java.util.Map<java.lang.String,java.lang.Object> |
LoadVariablesFrom(java.io.File f) |
static java.util.Map<java.lang.String,java.lang.Object> |
LoadVariablesFromString(java.lang.String str) |
static java.lang.String |
SerializeClassic(java.io.Serializable obj) |
static void |
SerializeTo(boolean append,
java.io.File f,
java.util.Map<java.lang.String,java.lang.Object> variables,
java.lang.Object... objs) |
static void |
SerializeTo(boolean append,
java.io.File f,
java.lang.Object... objs) |
static void |
SerializeTo(java.io.File f,
java.util.Map<java.lang.String,java.lang.Object> variables,
java.lang.Object... objs) |
static void |
SerializeTo(java.io.File f,
java.lang.Object... objs) |
static java.lang.String |
SerializeToString(java.util.Map<java.lang.String,java.lang.Object> variables,
java.lang.Object... objs) |
static java.lang.String |
SerializeToString(java.lang.Object... objs) |
static java.lang.StringBuilder |
SerializeToString(java.lang.StringBuilder source,
java.util.Map<java.lang.String,java.lang.Object> variables,
java.lang.Object... objs) |
static java.lang.StringBuilder |
SerializeToString(java.lang.StringBuilder source,
java.lang.Object... objs) |
static java.lang.String[] |
splitValues(java.lang.String s)
This function supposed to not be called by user.
|
static java.lang.Object |
UnserializeClassis(java.lang.String objStr) |
static <T> java.lang.String |
Var(java.lang.String name,
T value) |
static <T> java.lang.String |
Var(java.lang.String name,
T value,
boolean isValue) |
public static final Serializer.ProtocolRegistry PROTOCOL_REGISTRY
public static boolean useProtocolIfCan
public static boolean generateComments
public static java.text.DecimalFormat decimalFormatter
DecimalFormat will round decimal numbers to 3 decimal places (format pattern #.###)!
Set this on null and decimal numbers will not be formated! Do this when you need accuracy!public static java.util.Map<java.lang.String,java.lang.Object> globalVariables
public static <T> java.lang.String Var(java.lang.String name,
T value)
name - | Name of variable.value - | Value of variable.public static <T> java.lang.String Var(java.lang.String name,
T value,
boolean isValue)
name - | Name of variable.value - | Value of variable.isValue - | True if variables value supposed to by visible also during value loading.public static java.lang.String Comment(java.lang.String comment)
comment - | The comment...public static java.lang.String Code(java.lang.String code)
code - | Code to convert in to SerialX code form.public static void SerializeTo(java.io.File f,
java.lang.Object... objs)
f - | File to write in. This must be a text file (recommended extension .srlx).objs - | Objects to serialize using SerialX.public static void SerializeTo(boolean append,
java.io.File f,
java.lang.Object... objs)
append - | When true, the new objects will be appended to files content (same objects will be also appended if there are some)!f - | File to write in. This must be a text file (recommended extension .srlx).objs - | Objects to serialize using SerialX.public static java.lang.String SerializeToString(java.lang.Object... objs)
objs - | Objects to serialize using SerialX.public static java.lang.StringBuilder SerializeToString(java.lang.StringBuilder source,
java.lang.Object... objs)
source - | Source StringBuilder to serialize objects into!objs - | Objects to serialize using SerialX.StringBuilder with objects serialized in SerialX code.public static void SerializeTo(java.io.File f,
java.util.Map<java.lang.String,java.lang.Object> variables,
java.lang.Object... objs)
f - | File to write in. This must be a text file (recommended extension .srlx).variables - | Map with variables to serialize. Keys are names of variables and values are values.objs - | Objects to serialize using SerialX.public static void SerializeTo(boolean append,
java.io.File f,
java.util.Map<java.lang.String,java.lang.Object> variables,
java.lang.Object... objs)
append - | When true, the new objects will be appended to files content (same objects will be also appended if there are some)!f - | File to write in. This must be a text file (recommended extension .srlx).variables - | Map with variables to serialize. Keys are names of variables and values are values.objs - | Objects to serialize using SerialX.public static java.lang.String SerializeToString(java.util.Map<java.lang.String,java.lang.Object> variables,
java.lang.Object... objs)
variables - | Map with variables to serialize. Keys are names of variables and values are values.objs - | Objects to serialize using SerialX.public static java.lang.StringBuilder SerializeToString(java.lang.StringBuilder source,
java.util.Map<java.lang.String,java.lang.Object> variables,
java.lang.Object... objs)
source - | Source StringBuilder to serialize variables and objects into!variables - | Map with variables to serialize. Keys are names of variables and values are values.objs - | Objects to serialize using SerialX.StringBuilder with variables and objects serialized in SerialX code.public static java.lang.String SerializeClassic(java.io.Serializable obj)
throws java.io.IOException
obj - | Object to serialize using classic Java serialization.
Note: Slash will be replaced by back slash and Base64 padding with dash due to prevent conflict with SerialX syntax!java.io.IOException - - if an I/O error occurs while writing stream headerjava.lang.Base64public static java.lang.String LoadFileToString(java.io.File f)
f - | Source file.public static java.util.List<java.lang.Object> LoadFrom(java.io.File f)
f - | Text file with serialized objects using SerialX.ArrayList if file is empty.
You can use negative indexes to get objects from back of this array since 1.1.0 (-1 = last element)!public static java.util.List<java.lang.Object> LoadFromString(java.lang.String str)
str - | SerialX string with serialized objects.ArrayList if string is empty.
You can use negative indexes to get objects from back of this array since 1.1.0 (-1 = last element)!public static java.util.Map<java.lang.String,java.lang.Object> LoadVariablesFrom(java.io.File f)
f - | Text file with serialized variables and objects using SerialX.LinkedHashMap if source file contains no variables. Keys represents names of variables and values are values.
Global variables will be excluded if their value remain same.public static java.util.Map<java.lang.String,java.lang.Object> LoadVariablesFromString(java.lang.String str)
str - | SerialX string with serialized variables and objects.LinkedHashMap if source string contains no variables. Keys represents names of variables and values are values.
Global variables will be excluded if their value remain same.public static java.lang.Object UnserializeClassis(java.lang.String objStr)
throws java.io.IOException,
java.lang.ClassNotFoundException
objStr - | String to unserialize by classic Java serialization.
Note: Backslashes will be replaced by regular slashes and dashes with Base64 padding due to compatibility with SerialX syntax.java.io.IOException - - if an I/O error occurs while reading stream headerjava.lang.ClassNotFoundException - - Class of a serialized object cannot be found.Base64public static java.lang.String[] splitValues(java.lang.String s)
s - | String to split and check some syntax.